//
//  AppDelegate.m
//  mall
//
//  Created by 一米阳光 on 15/7/11.
//  Copyright (c) 2015年 seekool. All rights reserved.
//
#import "AppDelegate.h"
#import "ViewController.h"
#import "WXApi.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self setPushWithLaunchOptions:launchOptions];
    
    //设置微信
    [self setupWeixin];
    //统一app风格
    [self customizeUI];
    
    return YES;
}



//设置推送
- (void)setPushWithLaunchOptions:(NSDictionary *)launchOptions
{
    
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
   
}

//推送的token
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    //获取deviceToken
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:KDEVICE_TOKEN];
    
}

//设置微信 微信登录和微信支付
- (void)setupWeixin
{
    [WXApi registerApp:WEIXIN_APP_ID ]; // 微信开放平台
    [WXApi registerApp:WEIXIN_APP_PAY_ID withDescription:@"com.fumubang.fmb"]; //微信商户平台
}

//收到推送
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    [[NSNotificationCenter defaultCenter] postNotificationName:KPUSH_NOTICE object:userInfo];
    
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //点击推送过来的消息
    
}

//统一app风格
- (void)customizeUI
{
    [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithHexString:@"fcfcfc"]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor lt_orangeRedColor]}];
    [[UINavigationBar appearance] setTintColor:[UIColor lt_orangeRedColor]];
    
    [[UITableView appearance] setBackgroundColor:[UIColor colorWithHexString:@"#f5f5f5"]];
    [[UITableView appearance] setSeparatorColor:[UIColor colorWithHexString:@"#e9e9e9"]];
    
    [[UISwitch appearance] setOnTintColor:[UIColor lt_orangeRedColor]];
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-1000, -1000) forBarMetrics:UIBarMetricsDefault];
    [[UITabBar appearance] setTintColor:[UIColor lt_orangeRedColor]];
    [[UITabBar appearance] setBarTintColor:[UIColor colorWithHexString:@"#fcfcfc"]];
}



- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
